package com.example.demo.server.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.annotation.ApiDesc;
import com.example.demo.entity.base.PageRequestBean;
import com.example.demo.entity.base.PageResponseBean;
import com.example.demo.entity.base.ResponseEntity;
import com.example.demo.entity.server.ServerListenEntity;
import com.example.demo.entity.server.ServerReportEntity;
import com.example.demo.server.service.ServerListenService;

@RestController
@RequestMapping(value="/serverlisten")
public class ServerListenController {
	
	@Autowired
	private ServerListenService serverListenService;
	
	@ApiDesc("查看服务报告")
	@RequestMapping(value="/viewserverreport")
	public Object viewServerReport(HttpServletRequest request,@RequestParam String server_id) {
		
		ResponseEntity<ServerReportEntity>  ret = serverListenService.viewServerReport(server_id);
		
		return ret;		
	}
	
	@ApiDesc("查询服务状态")
	@RequestMapping(value="/querylistenedserver")
	public Object queryListenedServer(HttpServletRequest request,PageRequestBean<ServerListenEntity> pagerequest,ServerListenEntity serverParam) {
		
		pagerequest.setParams(serverParam);
		
		ResponseEntity<PageResponseBean<ServerListenEntity>> ret = serverListenService.queryListenedServer(pagerequest);
		
		return ret;		
	}
	
	@ApiDesc("删除服务")
	@RequestMapping(value="/deleteserver")
	public Object deleteServer(HttpServletRequest request,@RequestParam String key_id) {
		
		ResponseEntity<String> ret = serverListenService.deleteServer(key_id);
		
		return ret;		
	}
	
	@ApiDesc("修改服务属性")
	@RequestMapping(value="/updateserverparam")
	public Object updateServerParam(HttpServletRequest request,ServerListenEntity serverListenEntity) {
    	
    	ResponseEntity<String> ret = serverListenService.updateServerParam(serverListenEntity);
    	
    	return ret;		
	}
	
	@ApiDesc("添加监听服务")
	@RequestMapping(value="/addlistenserver")
	public Object addListenServer(HttpServletRequest request,ServerListenEntity serverListenEntity) {
    	
    	ResponseEntity<String> ret = serverListenService.addListenServer(serverListenEntity);
    	
    	return ret;		
	}
}
